<?php

class Photo extends Controller {
	
	function index() {
            global $session;
            
            $this->set('title','YOU - Photo');
            $session->set('status',$session->get('stat_upload'));
            $session->set('stat_upload',0);

            //$this->_render_header = false;
            //$this->_auto_render = false;
            if(isset($_GET['ajax'])) {
                $this->_render_header = false;
                //$this->_auto_render = false;
            }
            
            /*if(isset($_GET['ajax'])) {
                $this->_render_header = false;
                $this->_auto_render = false;
                $this->render();
            }*/
		/*global $session;
		$i = 0;
        $user_id = $session->get('userid');
		$res = $this->PhotoModel->query('select * from foto where iduser=\''.mysql_real_escape_string($user_id).'\'');
		$profpict = array();
		foreach ($profpict as $value)
		{
			$this->set('');
			$i = $i + 1;
		} */ 
		
                //refresh field buat foto2 yang pernah diupload..
	}

        function upload() {
            global $session;

            $session->set('stat_upload', 1);
            $user_id = $session->get('userid');
            $res = $this->PhotoModel->query('select * from user where iduser=\''.mysql_real_escape_string($user_id).'\'');
            $user_name = $res[0]['User']['username'];
            $session->set('fullname',$res[0]['User']['fullname']);
            $field = array();
            $field['iduser'] = $user_id;
            $field['username'] = $user_name;
            $field['idkategori'] = $_POST['kateg'];
            $field['hak_akses'] = $_POST['access'];
            $field['hak_komen'] = $_POST['comment'];
            $field['deskripsi'] = $_POST['desc'];
            $field['idkey'] = $_POST['key'];
            $field['tgl_foto'] = $_POST['tgl_ambil'];
            $field['pp'] = $_FILES['fphoto'];
            $this->PhotoModel->upload($field);
            $this->_auto_render = false;
            $this->redirect(BASE_PATH.'photo/index');
        }
	
	function beforeAction(){
		$this->set('title',null);
	}
	

}
